package com.pstreets.lwuit.demo.widgets;

import com.sun.lwuit.Command;
import com.sun.lwuit.Display;
import com.sun.lwuit.Form;
import com.sun.lwuit.TextField;
import com.sun.lwuit.animations.CommonTransitions;
import com.sun.lwuit.impl.midp.VKBImplementationFactory;
import com.sun.lwuit.impl.midp.VirtualKeyboard;
import com.sun.lwuit.layouts.BorderLayout;
import com.sun.lwuit.plaf.UIManager;
import com.sun.lwuit.util.Resources;
import javax.microedition.midlet.MIDlet;

/**
 * @author james
 */
public class VKNewLanguageDemo extends MIDlet {

    private static final String[][] DEFAULT_HEBREW = new String[][]{
        {"\u05e7", "\u05e8", "\u05d0", "\u05d8", "\u05d5", "\u05df", "\u05dd",
            "\u05e4", "$Delete$"},
        {"\u05e9", "\u05d3", "\u05d2", "\u05db", "\u05e2", "\u05d9", "\u05d7",
            "\u05dc", "\u05da"},
        {"\u05d6", "\u05e1", "\u05d1", "\u05d4", "\u05e0", "\u05de", "\u05e6",
            "\u05ea", "\u05e5"},
        {"$Mode$", "$Space$", "\u05E3", "$OK$"}};

    public static class HebrewK extends VirtualKeyboard {

        public HebrewK() {
            addInputMode("?05d0?05d1?05d2", DEFAULT_HEBREW);
            setInputModeOrder(new String[]{"?05d0?05d1?05d2", QWERTY_MODE,
                        NUMBERS_SYMBOLS_MODE, NUMBERS_MODE, SYMBOLS_MODE
                    });
        }
    }

    public void startApp() {

        VKBImplementationFactory.init(HebrewK.class);

        //init the LWUIT display
        Display.init(this);

        //setting the application theme
        try {
            Resources r = Resources.open("/LWUITtheme.res");
            UIManager.getInstance().setThemeProps(r.getTheme(r.getThemeResourceNames()[0]));
        } catch (Exception e) {
        }


        Form mainForm = new Form("TextField  Demo");

        mainForm.setLayout(new BorderLayout());

        TextField textfield = new TextField();
        textfield.setText("This is a text field");

        mainForm.addComponent(BorderLayout.CENTER, textfield);

        mainForm.setTransitionOutAnimator(CommonTransitions.createFade(400));

        mainForm.addCommand(new Command("Left soft key", 2));
        mainForm.addCommand(new Command("Right Soft key", 2));

        mainForm.show();


    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}
